package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.GasBalance;
import com.ruoyi.base.service.IGasBalanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author hw
 * @date 2023-01-07
 */
@RestController
@RequestMapping("/base/balance")
public class GasBalanceController extends BaseController
{
    @Autowired
    private IGasBalanceService gasBalanceService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('base:balance:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasBalance gasBalance)
    {
        startPage();
        List<GasBalance> list = gasBalanceService.selectGasBalanceList(gasBalance);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PreAuthorize("@ss.hasPermi('base:balance:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasBalance gasBalance)
    {
        List<GasBalance> list = gasBalanceService.selectGasBalanceList(gasBalance);
        ExcelUtil<GasBalance> util = new ExcelUtil<GasBalance>(GasBalance.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:balance:query')")
    @GetMapping(value = "/{balanceId}")
    public AjaxResult getInfo(@PathVariable("balanceId") Long balanceId)
    {
        return success(gasBalanceService.selectGasBalanceByBalanceId(balanceId));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('base:balance:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasBalance gasBalance)
    {
        gasBalance.setCreateBy(getUsername());
        return toAjax(gasBalanceService.insertGasBalance(gasBalance));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('base:balance:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasBalance gasBalance)
    {
        return toAjax(gasBalanceService.updateGasBalance(gasBalance));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('base:balance:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{balanceIds}")
    public AjaxResult remove(@PathVariable Long[] balanceIds)
    {
        return toAjax(gasBalanceService.deleteGasBalanceByBalanceIds(balanceIds));
    }
}
